package com.yc.cinema.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.yc.cinema.bean.FilmInfo;
import com.yc.cinema.service.IFilmInfoService;
import com.yc.cinema.service.impl.FilmInfoServiceImpl;
import com.yc.cinema.util.RequestParamUtil;

@WebServlet("/info/*")
public class FilmInfoController extends BaseController {
	private static final long serialVersionUID = 1754892969928360685L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req,resp);
	}
	
	/**
	 * 发布电影
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void add(HttpServletRequest request, HttpServletResponse response) throws IOException {
		FilmInfo fi = RequestParamUtil.getParams(request, FilmInfo.class);
		IFilmInfoService filmInfoService = new FilmInfoServiceImpl();
		int result = filmInfoService.update(fi);
		if(result > 0 ) {
			this.send(response, 200, result);
			return;
		}
		
		this.send(response, 600, "暂无数据");
	}
	
	/**
	 * 查询电影信息
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	public void check(HttpServletRequest request, HttpServletResponse response) throws IOException {
		FilmInfo fi = RequestParamUtil.getParams(request, FilmInfo.class);
		IFilmInfoService filmInfoService = new FilmInfoServiceImpl();
		List<FilmInfo> result = filmInfoService.findAll(fi);
		if(result != null ) {
			this.send(response, 200, result);
			return;
		}
		
		this.send(response, 600, "暂无数据");
	}
}
